home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Devices / NuBus⁄Slot Manager / ROM Build⁄Download 3.2.4 / CRCPatch folder / crcCalc.a next >
Encoding:
Text File  |  1995-05-25  |  4.0 KB  |  140 lines  |  [TEXT/MPS ]

  1. ;=====================================================================
  2. ;
  3. ; Copyright Apple Computer, Inc. 1986,1995
  4. ; All Rights Reserved
  5. ;
  6. ;=====================================================================
  7. ;
  8. ;    File           : CRCCalc.a
  9. ;    Author         : xxxxxx xxxxxx, July 30, 1986.
  10. ;    Description    : This file contains the CRC calculation.
  11. ;    Revised        : 05/25/95 fixed typo in word "incorporated", updated
  12. ;                    copyright date
  13. ;                 10/29/92    incorporated Paul G's fix for ROM size 
  14. ;                    up to 2Gbytes.  Thanks, Paul!
  15. ;                  
  16. ;
  17. ;=====================================================================
  18.  
  19. ;=====================================================================
  20. ;    Initial Assembler Directives
  21. ;=====================================================================
  22. ;Include files
  23.                 INCLUDE    'SysEQU.a'
  24.                 INCLUDE    'ROMEqu.a'        ;Declaration ROM EQU's
  25.                 INCLUDE    'SlotEqu.a'
  26.  
  27. ;=====================================================================
  28. ; _CalcCRC : Calculate CRC
  29. ;
  30. ; PROCEDURE _CalcCRC(SizeCode,DataPtr,crc);
  31. ;=====================================================================
  32. _CalcCRC        PROC    EXPORT
  33.  
  34. ;VAR
  35. RetnAddr$a        EQU        A0
  36. DataPtr$a        EQU        A1
  37. crcAdrL$a        EQU        A2
  38. crcAdrH$a        EQU        A3
  39. Temp$a            EQU        A4
  40. TopOfData$a        EQU        A5
  41.  
  42. SizeCode$d        EQU        D0
  43. crcPos$d        EQU        D1
  44. crc$d            EQU        D2
  45. Temp$d            EQU        D3
  46. Index$d            EQU        D4
  47.  
  48. ;  Define stack-frame
  49. StackFrame        RECORD {A6Link},DECR
  50. SizeCode        DS.L    1            ;size of code
  51. DataPtr            DS.L    1            ;pointer to data
  52. crc@            DS.L    1            ;VAR crc:longint
  53. Return            DS.L    1            ;Return address
  54. A6Link            DS.L    1            ;Old A6
  55.                 ENDR
  56.  
  57. ;  Other
  58. dataPtr           EQU         $4                        ; [handle]
  59.  
  60. ;----------------------------------------------------------------------
  61. ; _CalcCRC
  62. ;----------------------------------------------------------------------
  63. ;BEGIN 
  64. ;;;;;                WITH    VDPageInfo, SlotIntQElement
  65.                     WITH    FHeaderRec, StackFrame
  66.                     
  67. ;  Allocate local vars
  68.                 LINK    A6,#0
  69.                 MOVEM.L    A2-A5/D3-D4,-(SP)                ;Save registers
  70.                 
  71.                 
  72. ;  Calculate the address of the crc value.
  73.                 MOVE.L    SizeCode(A6),TopOfData$a        ;TopOfData$a := Top of data
  74.                 ADD.L    DataPtr(A6),TopOfData$a
  75.                 
  76.                 MOVE.L    TopOfData$a,crcAdrL$a            ;crcAdrL$a := TopOfData$a - (fhBlockSize-FH_crc)  {Addr of crc MSB}
  77.                 SUB.L    #fhBlockSize-fhCRC,crcAdrL$a
  78.                 MOVE.L    crcAdrL$a,crcAdrH$a                
  79.                 ADD.L    #3,crcAdrH$a                    ;Addr of crc LSB
  80.                 
  81.                 
  82. ;  Determine the size of the declaration data to be checked.
  83.                 MOVE.L    TopOfData$a,Temp$a                ;Temp$a := TopOfData$a - (fhBlockSize-FH_Length)  {Addr of Length field}
  84.                 SUB.L    #fhBlockSize-fhLength,Temp$a    ;Index := length of crc data.
  85.                 MOVE.L    (Temp$a),Index$d                    
  86.                 SUBQ.L    #1,Index$d                        ;Adjust index for DBF
  87.  
  88.                 MOVEQ    #0,crc$d                        ;crc$d := 0
  89.                 MOVE.L    DataPtr(A6),DataPtr$a            ;DataPtr$a := pointer to data
  90.             
  91.                 MOVE.L    SizeCode(A6),Temp$d                ;Adjust DataPtr$a
  92.                 SUB.L    Index$d,Temp$d
  93.                 ADD.L    Temp$d,DataPtr$a
  94.                 SUB.L    #1,DataPtr$a
  95.                 
  96.                 
  97. ;  Calc the crc value.
  98.                 MOVEQ    #0,Temp$d                        ;Temp$d := 0
  99.  
  100.                                                         ;REPEAT
  101. Repeat            ROL.L    #1,crc$d                        ;  Rotate-left the crc value.
  102.  
  103.                 CMP.L    crcAdrL$a,DataPtr$a                ;  IF DataPtr$a IN [crcAdrL$a..crcAdrH$a] THEN
  104.                 BLT.S    C10
  105.                 CMP.L    crcAdrH$a,DataPtr$a
  106.                 BGT.S    C10
  107.  
  108.                 ADDQ.L    #1,DataPtr$a                    ;    DataPtr$a := DataPtr$a + 1 {Do not include crc in calculation}
  109.                 BRA.S    Until                            
  110.                                                         ;  ELSE
  111. C10                MOVE.B    (DataPtr$a)+,Temp$d                ;    Temp$d := DataPtr$a^; DataPtr$a := DataPtr$a + 1
  112.                 ADD.L    Temp$d,crc$d                    ;    crc$d := crc$d + Temp$d
  113.  
  114. Until
  115. ;!pg 1/27/92
  116. ;!                DBF        Index$d,Repeat
  117.                 subq.l    #1,Index$d                        ;!pg 1/27/92    ;Index$d-=1
  118.                 bpl.s    Repeat                            ;!pg 1/27/92    ;UNTIL Index$d < 0
  119.  
  120. ;  Patch in the crc result.
  121.                 MOVE.L    crc$d,(crcAdrL$a)
  122.                 
  123.  
  124. ;  Move crc result to calling routine.
  125.                 MOVE.L    crc@(A6),Temp$a
  126.                 MOVE.L    crc$d,(Temp$a)
  127.                 
  128.  
  129. ;  Restore globals, cleanup stack & return        
  130. End                MOVEM.L    (SP)+,A2-A5/D3-D4                ;Restore registers
  131.                 UNLK    A6                                ;Clear stack frame of local vars
  132.                 MOVE.L    (SP)+,RetnAddr$a                ;Remove return address
  133.                 ADD.L    #12,SP                            ;Clear stack-frame of parameters
  134.                 JMP        (RetnAddr$a)                    ;Return
  135.                 
  136.                 ENDWITH    
  137.                 
  138.                 ENDP
  139.                 
  140.                 END